from manim import *



class math1(Scene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
              
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])   

        #特征碎片文本

        text0=MarkupText("<b><i>Summary：</i></b>",color=PINK).scale(5.0).move_to([-35,17.5,0])
        text1=Tex(r"\text{收获1张特征碎片}",color=YELLOW
                  ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0, 0, 0])
        self.play(Write(text0),Create(text1))
        self.wait(0.5)
        text2=Tex(r"\text{1张特征碎片}",color=YELLOW
                  ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0, 0, 0])
        self.play(Transform(text1,text2),Uncreate(text1),text2.animate.move_to([-17,17.5,0]),run_time=1)
        self.wait(0.5)


        #中心主题+框框标记
        text1 = Tex(r"\text{证明数列极限收敛}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Write(text1))
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-35, 0, 0])
        self.play(Create(rectangle))
        self.wait(0.5)
        #箭头引出
        arrow = Arrow(start=[-23,2.5,0],end=[-15,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本2
        text2 = Tex(r"\text{夹逼定理}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-7.5,10,0])
        self.play(Write(text2))
        self.wait(0.5)

        #箭头1引出
        arrow1 = Arrow(start=[-23,-2.5,0],end=[-15,-5,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow1))
        #文本3
        text3 = Tex(r"\text{单调有界}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-7.5,-5,0])
        self.play(Write(text3))
        self.wait(0.5)



        text4 = Tex(r"$y=f\left( x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-10,0])
        self.play(Write(text4))
        self.wait(0.5)
        text5 = Tex(r"$|f'\left( x\right)|  $",color=YELLOW_C
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,-15,0])
        self.play(Write(text5))
        self.wait(0.5)

         #箭头引出
        arrow2 = Arrow(start=[-30,-13,0],end=[-25,-12,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2))
        #文本
        text6 = Tex(r" $<1$\text{夹逼定理}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-16,-12,0])
        self.play(Write(text6))
        self.wait(0.5)

        #箭头1引出
        arrow3 = Arrow(start=[-30,-17,0],end=[-25,-18,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow3)) 
        #文本
        text7 = Tex(r"$\geq 1$\text{单调有界}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-16,-18,0])
        self.play(Write(text7))
        self.wait(0.5)

        text13 = Tex(r"$0\leq \left| x_{n+1}-a\right| =\left| f\left( x_{n}\right) -f\left( a\right) \right| =\left| f'\left( \xi \right) \right| \cdot \left| x_{n}-a\right| $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,4,0])
        self.play(Write(text13))
        self.wait(0.5)
        #部分文本淡出
        text14 = Tex(r"$\leq \ldots \leq \left| f'\left( \xi _{n}\right) _{\max }\right| ^{n-1}\cdot \left| x_{1}-a\right| $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-1,0])
        self.play(Write(text14))
        self.wait(0.5)
        #框框快速闪动
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=16,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle3.move_to([19, -1, 0])
        self.play(Create(rectangle3))
        self.wait(0.5)
        text15 = Tex(r"$ <1$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([17.5,-6,0])
        self.play(Write(text15))
        self.wait(0.5)
        self.play(FadeOut(rectangle3,text15)) 
        #框框标记

        rectangle4=Rectangle(color=BLUE,fill_opacity=0.0,width=28,height=5 
                            ,stroke_color=GREEN_D,stroke_width=20)
        rectangle4.move_to([25, -1, 0]) 
        self.play(Create(rectangle4))
        self.wait(0.5)
        #箭头+文本
        arrow2 = Arrow(start=[40,-1,0],end=[45,-1,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2))
        #文本
        text16 = Tex(r"\text{0}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([47,-1,0])
        self.play(Write(text16))
        self.wait(0.5)
        #文本

        text11 = Tex(r"$f\left( x\right) =\arccos \left( \dfrac{\sin x}{x}\right) $",color=YELLOW_C
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,-15,0])
        self.play(Write(text11))
